package com.huaqing.memory;

import com.huaqing.result.Result;
import lombok.Data;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @program: javatrainingfirstweek
 * @Description: 双检锁/双重校验锁
 * @author: Mr.Cheng
 * @date: 2022/4/10 4:02 下午
 */
@Data
public class SingletonMemory {

    private List<Result> resultList = new CopyOnWriteArrayList<Result>();

    private static  boolean qwe = false;

    private volatile static SingletonMemory singleton;

    private SingletonMemory(){
        if (qwe==false){
            qwe = true;
        }else {
            throw new RuntimeException("这是单例对象!");
        }
    }

    public static SingletonMemory getSingleton(){
        if(singleton == null){
            synchronized (SingletonMemory.class){
                if(singleton == null){
                    singleton = new SingletonMemory();
                }
            }
        }
        return singleton;
    }

}
